package com.personal.system.controller.seckill;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.personal.common.result.Result;
import com.personal.system.entity.seckill.Goods;
import com.personal.system.entity.seckill.SeckillGoods;
import com.personal.system.service.SeckillService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@Api(tags = "商品控制器")
@RequestMapping("/goods")
@RestController
public class GoodsController {

    @Resource
    private SeckillService seckillService;

    @GetMapping("/getPageList/{page}/{limit}")
    public Result getPageList(@PathVariable Long page, @PathVariable Long limit) {

        Page<Goods> pageParam = new Page<>(page, limit);
        IPage<Goods> pageModel = (IPage<Goods>)seckillService.getSeckillGoodsList(pageParam);
        return Result.ok(pageModel);
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {

        return Result.ok( seckillService.getById(id));
    }

    @PostMapping("/updateGoods")
    public Result updateGoods(@RequestBody SeckillGoods goods) {

        return Result.ok( seckillService.updateGoods(goods));
    }

}
